package com.goods.controller.business;

import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.system.PageVO;
import com.goods.business.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;



@Api(tags = "业务管理-物资类别接口")
@RestController
@RequestMapping("/business/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;


    @ApiOperation("分页查询物资类别")
    @GetMapping("/categoryTree")
    public ResponseBean categoryTree(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){
        PageVO<ProductCategoryTreeNodeVO> categoryList =  productCategoryService.categoryTree(pageNum,pageSize);
        return ResponseBean.success(categoryList);
    }
    @ApiOperation("查询时添加父类")
    @GetMapping("/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){

        List<ProductCategoryTreeNodeVO> TreeList = productCategoryService.getParentCategoryTree();
        return ResponseBean.success(TreeList);
    }
    @ApiOperation("物资类别添加")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductCategoryVO productCategoryVO){
        if (productCategoryVO == null){
            return ResponseBean.error("添加数据为空");
        }
        productCategoryService.add( productCategoryVO);
        return ResponseBean.success("添加成功");
    }
    @ApiOperation("修改")
    @GetMapping("/edit/{id}")
    public ResponseBean<ProductCategoryVO> edit(@PathVariable Long id){
        ProductCategoryVO edit = productCategoryService.edit(id);
        return ResponseBean.success(edit);
    }
    @ApiOperation("物资类别修改")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductCategoryVO productCategoryVO){

        return ResponseBean.success(productCategoryService.update(id,productCategoryVO));
    }
    @ApiOperation("物资类别删除")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        return ResponseBean.success(productCategoryService.delete(id));
    }


}
